//
//  PopViewController.m
//  Love trial1。0
//
//  Created by giantumbrella on 15/5/25.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "PopViewController.h"
#import "AppDelegate.h"
#import "CommonMacro.h"

#define Conunt 6
#define barItemWidth (double)self.view.frame.size.width/Conunt
@interface PopViewController ()


@end

@implementation PopViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
}

-(void)popView
{
//window 上添加一个视图
    //window上添加内容视图
    UIWindow *window=[[UIApplication sharedApplication].delegate window];
    UIView *aview=[[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    aview.tag=100;
    aview.alpha=0.1;
    [window addSubview:aview];
    UIView *bview=[[UIView alloc]init];
    bview.tag=101;
    bview.backgroundColor = UIColorWithRGBA(242, 242, 242, 1) ;
    bview.frame=CGRectMake(0, -120, window.frame.size.width, 60);
//    bview.backgroundColor = [UIColor blueColor];
    [window addSubview:bview];
     [self addSubViews];
    //给bview一个动画
    [UIView animateWithDuration:0.5 animations:^{
        bview.frame = CGRectMake(0, 63, window.frame.size.width, 50);
    }];

}


//给bview添加子视图
-(void)addSubViews{
    UIWindow *window=[[UIApplication sharedApplication].delegate window];
    UIView *bview=[window viewWithTag:101];
        for (int i = 0; i<6; i++) {
                UIButton *button = [[UIButton alloc] init];
            button.tag = 1000+i;
            [button setImageEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 10)];
            [button addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
            
            switch (i) {
                case 0:
                    [button setFrame:CGRectMake(0, 0, barItemWidth, 49)];
                    [button setImage:[UIImage imageNamed:@"食品"] forState:UIControlStateNormal];
                    [button setImage:[UIImage imageNamed:@"食品-选中"] forState:UIControlStateSelected];
                    button.selected=YES;
                    lastButton=button;
                    break;
                case 1:
                    [button setFrame:CGRectMake(barItemWidth, 0, barItemWidth, 49)];
                    [button setImage:[UIImage imageNamed:@"奶粉"] forState:UIControlStateNormal];
                    [button setImage:[UIImage imageNamed:@"奶粉-选中"] forState:UIControlStateSelected];
                    break;
                case 2:
                    [button setFrame:CGRectMake(barItemWidth*2, 0, barItemWidth, 49)];
                    [button setImage:[UIImage imageNamed:@"用品@2x"] forState:UIControlStateNormal];
                    [button setImage:[UIImage imageNamed:@"用品-选中@2x"] forState:UIControlStateSelected];
                    break;
                case 3:
                    [button setFrame:CGRectMake(barItemWidth*3, 0, barItemWidth, 49)];
                    [button setImage:[UIImage imageNamed:@"孕妈@2x"] forState:UIControlStateNormal];
                    [button setImage:[UIImage imageNamed:@"孕妈-选中@2x"] forState:UIControlStateSelected];
                    
                    break;
                case 4:
                    [button setFrame:CGRectMake(barItemWidth*4, 0, barItemWidth, 49)];
                    [button setImage:[UIImage imageNamed:@"学习@2x"] forState:UIControlStateNormal];
                    [button setImage:[UIImage imageNamed:@"学习-选中@2x"] forState:UIControlStateSelected];
                   
                    break;
                case 5:
                    [button setFrame:CGRectMake(barItemWidth*5, 0, barItemWidth, 49)];
                    [button setImage:[UIImage imageNamed:@"玩具@2x"] forState:UIControlStateNormal];
                    [button setImage:[UIImage imageNamed:@"玩具-选中@2x"] forState:UIControlStateSelected];
                   
                    break;
                    
                default:
                    break;
            }
             [bview addSubview:button];
       }
  
}

#pragma mark 按钮点击后出现的状况
-(void)tapAction:(UIButton *)btn{
    if (lastButton!=btn) {
        lastButton.selected=NO;
    }
    lastButton=btn;
    btn.selected=YES;
    
    UIWindow *window=[[UIApplication sharedApplication].delegate window];
    UIView *aview=[window viewWithTag:100];
    UIView *bview=[window viewWithTag:101];
    
    [UIView animateWithDuration:0.5 animations:^{
        bview.frame=CGRectMake(0, -120, window.frame.size.width, 60);
    } completion:^(BOOL finished) {
        [bview removeFromSuperview];
        [aview removeFromSuperview];
    }];

}

//点击保存按钮后退出当前页面
//-(void)dimiss:(id)sender{
//    UIWindow *window=[[UIApplication sharedApplication].delegate window];
//    UIView *aview=[window viewWithTag:100];
//    UIView *bview=[window viewWithTag:101];
//    
//    [UIView animateWithDuration:0.5 animations:^{
//        bview.frame=CGRectMake(0, -120, window.frame.size.width, 60);
//    } completion:^(BOOL finished) {
//       [bview removeFromSuperview];
//       [aview removeFromSuperview];
//    }];
//}

@end
